package com.ruoyi.report.controller;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.report.domain.TPopularizeLaw;
import com.ruoyi.report.service.ITPopularizeLawService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 普法文章Controller
 * 
 * @author administrator
 * @date 2025-02-16
 */
@Controller
@RequestMapping("/system/law")
public class TPopularizeLawController extends BaseController
{
    private String prefix = "system/law";

    @Autowired
    private ITPopularizeLawService tPopularizeLawService;

    @GetMapping()
    public String law()
    {
        return prefix + "/law";
    }

    /**
     * 查询普法文章列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TPopularizeLaw tPopularizeLaw)
    {
        startPage();
        List<TPopularizeLaw> list = tPopularizeLawService.selectTPopularizeLawList(tPopularizeLaw);
        return getDataTable(list);
    }

    /**
     * 导出普法文章列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPopularizeLaw tPopularizeLaw)
    {
        List<TPopularizeLaw> list = tPopularizeLawService.selectTPopularizeLawList(tPopularizeLaw);
        ExcelUtil<TPopularizeLaw> util = new ExcelUtil<TPopularizeLaw>(TPopularizeLaw.class);
        util.exportExcel(response,list, "law");
    }

    /**
     * 新增普法文章
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存普法文章
     */
    @PostMapping("/add")
    public AjaxResult addSave(@RequestBody TPopularizeLaw tPopularizeLaw)
    {
        return toAjax(tPopularizeLawService.insertTPopularizeLaw(tPopularizeLaw));
    }

    /**
     * 修改普法文章
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TPopularizeLaw tPopularizeLaw = tPopularizeLawService.selectTPopularizeLawById(id);
        mmap.put("tPopularizeLaw", tPopularizeLaw);
        return prefix + "/edit";
    }

    /**
     * 修改保存普法文章
     */
    @PostMapping("/edit")
    public AjaxResult editSave(@RequestBody TPopularizeLaw tPopularizeLaw)
    {
        return toAjax(tPopularizeLawService.updateTPopularizeLaw(tPopularizeLaw));
    }

    /**
     * 删除普法文章
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(@RequestBody Map<String,String> map)
    {
        return toAjax(tPopularizeLawService.deleteTPopularizeLawByIds(map));
    }
}
